//
//  HomeViewController.m
//  MiguMetaEntrance
//
//  Created by 易德强 on 2024/3/7.
//

#import "HomeViewController.h"
#import "SDCycleScrollView.h"
#import "MGMetaCell.h"
#import "MGHotInfoCell.h"

@interface HomeViewController ()<SDCycleScrollViewDelegate, UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, weak) IBOutlet UITableView *tableView;

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"统一入口";
    [self setupBanner];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MGMetaCell" bundle:nil] forCellReuseIdentifier:@"MGMetaCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MGHotInfoCell" bundle:nil] forCellReuseIdentifier:@"MGHotInfoCell"];
}

- (void)setupBanner {
    NSArray *imageNames = @[@"1", @"2", @"3"];
    // 本地加载 --- 创建不带标题的图片轮播器
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, 200) shouldInfiniteLoop:YES imageNamesGroup:imageNames];
    cycleScrollView.delegate = self;
    cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
    cycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    cycleScrollView.autoScrollTimeInterval = 3.0;//轮播时间间隔，默认1.0秒，可自定义
    self.tableView.tableHeaderView = cycleScrollView;
}

#pragma mark - tableview代理方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0) {
        MGMetaCell *cell  = [tableView dequeueReusableCellWithIdentifier:@"MGMetaCell"];
        return cell;
    }
    MGHotInfoCell *cell  = [tableView dequeueReusableCellWithIdentifier:@"MGHotInfoCell"];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0) {
        return 300;
    }

    return 500;
}

@end
